package com.assist.beans;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;

import com.assist.model.User;
import com.assist.service.IUserService;
import com.assist.service.impl.UserServiceImpl;

@ManagedBean(name="userInfoBean")
@SessionScoped
public class UserInfoBean  implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	User user;

	public UserInfoBean() {
		// TODO Auto-generated constructor stub
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        Long userId = (Long) session.getAttribute("loginUserId");
        System.out.println("User id"+userId);

        IUserService userService  = new UserServiceImpl();
		user = userService.getUserById(userId);
	}

	public String getFirstName() {
		return user.getFirstName();
	}

	public void setFirstName(String firstName) {
		user.setFirstName(firstName);
	}

	public String getLastName() {
		return user.getLastName();
	}

	public void setLastName(String lastName) {
		user.setLastName(lastName) ;
	}

	public String getUserName() {
		return user.getUserName();
	}

	public void setUserName(String userName) {
		user.setUserName(userName);
	}

	public String getGender() {
		return user.getGender();
	}

	public void setGender(String gender) {
		user.setGender(gender);
	}

	public String getMobile() {
		return user.getMobile();
	}

	public void setMobile(String mobile) {
		user.setMobile(mobile);
	}

	public String getBirthday() {
		return user.getBirthday();
	}

	public void setBirthday(String birthday) {
		user.setBirthday(birthday);
	}

	public String getPassword() {
		return user.getPassword();
	}

	public void setPassword(String password) {
		user.setPassword(password);
	}

	public String getPasswordConfirmation() {
		return user.getPasswordConfirmation();
	}

	public void setPasswordConfirmation(String passwordConfirmation) {
		user.setPasswordConfirmation (passwordConfirmation);
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public void returnToIndex(ActionEvent e) {
		try {
			FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	
	}



}
